package com.example.works;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;

public class Work06Intent extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work06_intent);

        findViewById(R.id.btn_01).setOnClickListener(this);
        findViewById(R.id.btn_02).setOnClickListener(this);
        findViewById(R.id.btn_03).setOnClickListener(this);
        findViewById(R.id.btn_04).setOnClickListener(this);
        findViewById(R.id.btn_05).setOnClickListener(this);
        findViewById(R.id.btn_06).setOnClickListener(this);
        findViewById(R.id.btn_07).setOnClickListener(this);
        findViewById(R.id.btn_08).setOnClickListener(this);

        //API24以上系统分享支持file:///开头
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        builder.detectFileUriExposure();
    }

    @Override
    public void onClick(View view) {
        String phoneNumber = "123456";
        switch (view.getId()) {
            case R.id.btn_01:
                Uri wenUri = Uri.parse("https://www.bilibili.com/video/BV19U4y1R7zV?p=40");
                Intent intent_01 = new Intent(Intent.ACTION_VIEW, wenUri);
                startActivity(intent_01);
                break;
            case R.id.btn_02:
                Intent intent_02 = new Intent();
                intent_02.setAction(Intent.ACTION_DIAL);
                startActivity(intent_02);
                break;
            case R.id.btn_03:
                Intent intent_03 = new Intent();
                intent_03.setAction(Intent.ACTION_DIAL);
                Uri uri = Uri.parse("tel:" + phoneNumber);
                intent_03.setData(uri);
                startActivity(intent_03);
                break;
            case R.id.btn_04:
                /*error*/
                /*Intent intent_04 = new Intent();
                intent_04.setAction(Intent.ACTION_SEND);
                startActivity(intent_04);*/
                Intent intent_04 = new Intent(Intent.ACTION_VIEW);
                intent_04.putExtra("sms_body", "The SMS text");
                intent_04.setType("vnd.android-dir/mms-sms");
                startActivity(intent_04);
                break;
            case R.id.btn_05:
                Intent intent_05 = new Intent();
                intent_05.setAction(Intent.ACTION_SENDTO);
                Uri uri_02 = Uri.parse("smsto:" + phoneNumber);
                intent_05.setData(uri_02);
                startActivity(intent_05);
                break;
            case R.id.btn_06:
                Intent intent_06 = new Intent(Intent.ACTION_VIEW);
                intent_06.setType("audio/*");
                intent_06.setData(Uri.parse("file:///sdcard/Music/配音文件.mp3"));
                intent_06.setPackage("com.salt.music");
                startActivity(intent_06);
                break;
            case R.id.btn_07:
                Uri uninstallUri = Uri.fromParts("package", "xxx", null);
                Intent intent_07 = new Intent(Intent.ACTION_DELETE, uninstallUri);
                startActivity(intent_07);
                break;
            case R.id.btn_08:
                Uri installUri = Uri.fromParts("package", "xxx", null);
                Intent intent_08 = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
                startActivity(intent_08);
                break;
            default:
                break;

        }
    }
}